package com.thread.www.test;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 并发实战，汽车跟踪器的容器类
 *
 * @Author: panjoy
 * @Description:
 * @Date: Created in 10:09 2017-06-14
 * @Modfied By:
 */
public class DelegatingVehicleTracker {
    private final ConcurrentHashMap<String, Point> locations;
    private final Map<String, Point> unmodifiableMap;

    public DelegatingVehicleTracker(Map<String, Point> points) {
        locations = new ConcurrentHashMap<String, Point>(points);
        unmodifiableMap = Collections.unmodifiableMap(points);

    }

    public Map<String, Point> getLocations() {
        //return unmodifiableMap;
        return locations;
    }

    public Point getLoction(String id) {
        return locations.get(id);
    }

    public void setLocations(String id, int x, int y) {
        if (locations.replace(id, new Point(x, y)) == null)
            throw new IllegalArgumentException("Invalid vehicle name" + id);
    }
}
